<%--
  Created by IntelliJ IDEA.
  User: hp
  Date: 2020/7/13
  Time: 1:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="true" %>
<html>
<head>
    <title>入库明细</title>
    <%@include file="/common/com.jsp"%>
</head>

<body>
<div id="root">
    <template>
        <Collapse active-key="1">
            <Panel name="Panel">
                多条件查询
                <p slot="content">
                    <i-form :label-width="60" inline >
                        <Form-Item label="商品名称">
                            <i-input type="text" v-model="InboundVo.name"></i-input>
                        </Form-Item>
                        <Form-Item label="订单号">
                            <i-Select v-model="InboundVo.poId" remote :remote-method="getPolist">
                                <i-Option :value="''">--查看全部--</i-Option>
                                <i-Option v-for="po in Polist" :value="po.id" :key="po.id">{{po.number}}</i-Option>
                            </i-Select>
                        </Form-Item>
                        <Form-Item label="入库数量">
                            <i-input type="text" v-model="InboundVo.quantity"></i-input>
                        </Form-Item>
                        <Form-Item label="入库时间">
                            <Date-Picker type="date" placeholder="start date" style="width: 200px" v-model="InboundVo.inboundDateg"></Date-Picker>
                            <Date-Picker type="date" placeholder="end date" style="width: 200px" v-model="InboundVo.inboundDatel"></Date-Picker>
                        </Form-Item>
                        <i-button type="primary" shape="circle" icon="ios-search" @click="pageNo=1;getInboundlist();" >搜索</i-button>
                    </i-form>
                </p>
            </Panel>
        </Collapse>

    </template>
    <card>
        <i-button type="primary" shape="circle" @click="getInboundlist()"><Icon type="ios-refresh"></Icon>刷新</i-button>
        <i-button type="primary" shape="circle" @click="add">添加入库商品</i-button>
    </card>
    <i-table :columns="columns" :data="data" border stripe height="400">
        <template slot-scope="{row,index}" slot="mxLingcode">
            {{row.mx.mxLingcode}}
        </template>
        <template slot-scope="{row,index}" slot="action">
            <i-Button type="info" @click="ckmx(row,index)">查看明细</i-Button>
            <i-Button type="info" @click="addissue(row,index)">进入库存</i-Button>
        </template>
        <template slot-scope="{row,index}" slot="actioni">
            <i-Button type="info" @click="update(row,index)">修改</i-Button>
            <i-Button type="error" @click="del(row,index)">删除</i-Button>
        </template>
    </i-table>
    <Modal v-model="modaladd" title="添加入库商品" @on-ok="doadd">
        <i-form :label-width="80">
            <Form-Item label="商品名称">
                <i-input v-model="Inbound.name" id="ee"></i-input>
            </Form-Item>

            <Form-Item label="商品类型">
                <i-input v-model="Inbound.inboundType"></i-input>
            </Form-Item>
            <Form-Item label="订单号">
                <i-Select v-model="Inbound.poId" remote :remote-method="getPolist">
                    <i-Option :value="''">--选择订单号--</i-Option>
                    <i-Option v-for="po in Polist" :value="po.id" :key="po.id">{{po.number}}</i-Option>
                </i-Select>
            </Form-Item>
            <Form-Item label="商品成本价">
                <i-input v-model="Inbound.inboundUnitprice"></i-input>
            </Form-Item>
            <Form-Item label="商品销售价">
                <i-input v-model="Inbound.inboundTotalprice"></i-input>
            </Form-Item>
            <Form-Item label="入库数量">
                <i-input v-model="Inbound.quantity"></i-input>
            </Form-Item>
            <Form-Item label="商品供应商">
                <i-Select v-model="Inbound.insuId" remote :remote-method="getsupplierlist">
                    <i-Option :value="''">--选择供应商--</i-Option>
                    <i-Option v-for="supplier in supplierlist" :value="supplier.id" :key="supplier.id">{{supplier.name}}</i-Option>
                </i-Select>
            </Form-Item>
            <Form-Item label="商品备注">
                <i-input v-model="Inbound.descr"></i-input>
            </Form-Item>

        </i-form>
    </Modal>
    <Modal v-model="modalupdate" title="修改入库商品" @on-ok="doupdate">
        <i-form :label-width="80">
            <Form-Item label="商品名称">
                <i-input v-model="Inbound.name"></i-input>
            </Form-Item>

            <Form-Item label="商品类型">
                <i-input v-model="Inbound.inboundType"></i-input>
            </Form-Item>
            <Form-Item label="订单号">
                <i-Select v-model="Inbound.poId" remote :remote-method="getPolist">
                    <i-Option :value="''">--选择订单号--</i-Option>
                    <i-Option v-for="po in Polist" :value="po.id" :key="po.id">{{mx.mxLingcode}}</i-Option>
                </i-Select>
            </Form-Item>
            <Form-Item label="商品成本价">
                <i-input v-model="Inbound.inboundUnitprice"></i-input>
            </Form-Item>
            <Form-Item label="商品销售价">
                <i-input v-model="Inbound.inboundTotalprice"></i-input>
            </Form-Item>
            <Form-Item label="入库数量">
                <i-input v-model="Inbound.quantity"></i-input>
            </Form-Item>
            <Form-Item label="商品备注">
                <i-input v-model="Inbound.descr"></i-input>
            </Form-Item>
            <Form-Item label="商品供应商">
                <i-Select v-model="Inbound.insuId" remote :remote-method="getsupplierlist">
                    <i-Option :value="''">--选择供应商--</i-Option>
                    <i-Option v-for="supplier in supplierlist" :value="supplier.id" :key="supplier.id">{{supplier.name}}</i-Option>
                </i-Select>
            </Form-Item>
        </i-form>

        </i-form>
    </Modal>
    <Modal v-model="modalckmx" title="查看入库商品" width="500">

        <i-form :label-width="80">
            <Form-Item label="商品名称:">
                {{Inbound.name}}
            </Form-Item>
            <Form-Item label="商品类型:">
                {{Inbound.inboundType}}
            </Form-Item>
            <%--<Form-Item label="订单号">--%>
            <%--&lt;%&ndash;{{row.Po.number}}&ndash;%&gt;--%>
            <%--</Form-Item>--%>
            <Form-Item label="入库数量:">
                {{Inbound.quantity}}
            </Form-Item>
            <Form-Item label="商品单价:">
                {{Inbound.inboundUnitprice}}
            </Form-Item>
            <Form-Item label="商品总价:">
                {{Inbound.inboundTotalprice}}
            </Form-Item>
            <Form-Item label="入库时间:">
                {{Inbound.inboundDate}}
            </Form-Item>
            <Form-Item label="商品备注:">
                {{Inbound.descr}}
            </Form-Item>
        </i-form>

    </Modal>
    <Modal v-model="modaladdissue" title="添加入库商品" @on-ok="doaddissue">
        <h3>是否确定入库此商品?</h3>
    </Modal>
    <template>
        <Page :total="total"
              show-elevator
              :page-size="pageSize"
              style="margin-left: 340px;margin-top:15px"
              :current.sync="pageNo"
              show-sizer
              prev-text="上一页"
              next-text="下一页"
              :page-size-opts="[5,10,20,30,40]"
              show-total
              @on-page-size-change="pageSize=arguments[0];getInboundlist();"
              @on-change="getInboundlist"/>
    </template>
</div>
</body>
<script>
    new  Vue({
        el:"#root",
        data:{
            columns:[
                {title: "商品名称", key: "name"},
                {title:"订单号",slot:"mxLingcode"},
                {title: "入库数量", key: "quantity"},
                {title: "入库时间", key: "inboundDate"},
                {title:"查看",slot:"action"},
                {title:"其他操作",slot:"actioni"},

            ],
            data:[],
            InboundVo:{},
            goodslist:[],
            total:50,
            pageNo:1,
            pageSize:5,
            modaladd:false,
            modalupdate:false,
            modalckmx:false,
            Inbound:{},
            Po:{},
            modaloutbou:false,
            modaladdissue:false,
            Polist:[],
            supplierlist:[],
        },
        mounted(){
            // this.getgoodslist();
            this.getInboundlist();
            this.getPolist();
            this. getsupplierlist();
        },
        methods:{
            getInboundlist(){
                axios.get(`${apath}/inbound/pagelist/${this.pageSize}/${this.pageNo}`,{params:this.InboundVo})
                    .then(({data})=>{
                        console.log(data.result);
                        this.data=data.result.record;
                        this.total=data.result.total;
                    })
            },
            getsupplierlist(){
                axios.get(`${apath}/supplier/list`).then(({data})=>{
                    this.supplierlist = data.result;

                })
            },
            getPolist(){
                axios.get(`${apath}/po/polist`).then(({data})=>{
                    this.Polist=data.result;
                })
            },
            add(){
                this.Inbound={};
                this.modaladd=true;
            },
            doadd(){
                let _this = this;
                this.modaladd=false;
                if (this.Inbound.name==null){
                    _this.$nextTick(()=>{
                        _this.modaladd=true;
                        iview.Message.error({
                            content:"商品名称不能为空"
                        });
                    });

                }else if (this.Inbound.inboundType==null) {
                    _this.$nextTick(()=>{
                        _this.modaladd=true;
                        iview.Message.error({
                            content:"商品类型不能为空"
                        });
                    });

                }else if (this.Inbound.poId==null){
                    _this.$nextTick(()=>{
                        _this.modaladd=true;
                        iview.Message.error({
                            content:"订单号不能为空"
                        });
                    });

                }else if (this.Inbound.quantity==null||this.Inbound.quantity<=0){
                    _this.$nextTick(()=>{
                        _this.modaladd=true;
                        iview.Message.error({
                            content:"商品数量不能为空且不能是0或小于0"
                        });
                    });

                }else if (this.Inbound.inboundUnitprice==null||this.Inbound.inboundUnitprice<=0){
                    _this.$nextTick(()=>{
                        _this.modaladd=true;
                        iview.Message.error({
                            content:"商品成本价格不能为空且不能是0或小于0"
                        });
                    });
                }else if (this.Inbound.inboundTotalprice==null||this.Inbound.inboundTotalprice<=0){
                    _this.$nextTick(()=>{
                        _this.modaladd=true;
                        iview.Message.error({
                            content:"商品销售价格不能为空且不能是0或小于0"
                        });
                    });
                }else if (this.Inbound.insuId==null){
                    _this.$nextTick(()=>{
                        _this.modaladd=true;
                        iview.Message.error({
                            content:"供货商不能为空"
                        });
                    });
                }else{
                    _this.$nextTick(()=>{
                        axios.post(`${apath}/inbound/inboundadd`,this.Inbound)
                            .then(({data})=>{
                                iview.Message.success({content:data.msg})
                                this.getInboundlist();
                            })
                    },500);
                    _this.modeladd=false;
                }
            },



            del(row,index){
                let _this=this;
                iview.Modal.confirm({
                    title:"是否确定删除?",
                    content:"此操作一旦确定无法返回,请谨慎使用",
                    onOk(){
                        axios.get(`${apath}/inbound/inbounddel/${row.id}`)
                            .then(({data})=>{
                                iview.Message.success({content: data.msg})

                                _this.getInboundlist();
                            })
                    },
                    onCancel(){
                        iview.Message.warning({
                            content:"取消删除"
                        })
                    }
                })
            },
            update(row,index){
                this.Inbound=row;
                this.modalupdate=true;
            },
            doupdate(){
                let _this = this;
                this.modaladd=false;
                if (this.Inbound.name==null||this.Inbound.name==""){
                    _this.$nextTick(()=>{
                        _this.modalupdate=true;
                        iview.Message.error({
                            content:"商品名称不能修改为空"
                        });
                    });

                }else if (this.Inbound.inboundType==null||this.Inbound.inboundType=="") {
                    _this.$nextTick(()=>{
                        _this.modalupdate=true;
                        iview.Message.error({
                            content:"商品类型不能修改为空"
                        });
                    });

                }else if (this.Inbound.poId==null){
                    _this.$nextTick(()=>{
                        _this.modalupdate=true;
                        iview.Message.error({
                            content:"订单号不能修改为空"
                        });
                    });

                }else if (this.Inbound.quantity==null||this.Inbound.quantity<=0){
                    _this.$nextTick(()=>{
                        _this.modalupdate=true;
                        iview.Message.error({
                            content:"商品数量不能修改为空且不能是0或小于0"
                        });
                    });

                }else if (this.Inbound.inboundUnitprice==null||this.Inbound.inboundUnitprice<=0){
                    _this.$nextTick(()=>{
                        _this.modalupdate=true;
                        iview.Message.error({
                            content:"商品成本价格不能修改为空且不能是0或小于0"
                        });
                    });
                }else if (this.Inbound.inboundTotalprice==null||this.Inbound.inboundTotalprice<=0){
                    _this.$nextTick(()=>{
                        _this.modalupdate=true;
                        iview.Message.error({
                            content:"商品销售价格不能修改为空且不能是0或小于0"
                        });
                    });
                }else if (this.Inbound.insuId==null){
                    _this.$nextTick(()=>{
                        _this.modalupdate=true;
                        iview.Message.error({
                            content:"供货商不能修改为空"
                        });
                    });
                }else{
                    _this.$nextTick(()=>{
                        axios.post(`${apath}/inbound/inboundupdate`,this.Inbound)
                            .then(({data})=>{
                                iview.Message.success({content:data.msg})
                                this.getInboundlist();
                            })
                    },500);
                    _this.modalupdate=false;
                }
            },

            ckmx(row,index){
                this.Inbound=row;
                this.modalckmx=true

            },
            dockmx(){
                this.getOutboundlist();
            },
            addissue(row,index){
                this.Inbound=row;
                this.modaladdissue=true;
            },

            doaddissue(){
                axios.post(`${apath}/inbound/deliveredaddRk`,this.Inbound)
                    .then(({data})=>{
                        iview.Message.success({content:data.msg})
                        this.getInboundlist();
                    })
            }

        }

    })
</script>
</html>
